package com.cheyun.netsalev3.bean

import androidx.databinding.BaseObservable
import androidx.databinding.Bindable
import com.cheyun.netsalev3.BR
import com.cheyun.netsalev3.widget.MyDialog
import java.io.Serializable

class KeyValueParam() : BaseObservable(), Serializable {
    constructor(key: String, value: String) : this() {
        this.value = value
        this.key = key
        this.poptitle = "请选择${key.replace(":", "")}"
    }

    @get:Bindable
    var key: String = ""
        set(key) {
            field = key
            notifyPropertyChanged(BR.key)
        }
    @get:Bindable
    var position = 0
        set(value) {
            field = value
            notifyPropertyChanged(BR.position)

        }
    @get:Bindable
    var isfood = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.isfood)
        }


    var poptitle = "请选择${key.replace(":", "")}"
    //是否可以编辑
    @get:Bindable
    var isEdit = true
        set(value) {
            field = value
            notifyPropertyChanged(BR.edit)
        }

    //是否为必须项
    @get:Bindable
    var isMust = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.must)
        }

    //是否可以操作
    @get:Bindable
    var isEnable = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.enable)
        }

    @get:Bindable
    var isMore = true
        set(value) {
            field = value
            notifyPropertyChanged(BR.more)
        }

    //是否可以多选
    @get:Bindable
    var isMultiple = false
        set(value) {
            field = value
            notifyPropertyChanged(BR.enable)
        }
    constructor(key: String, type: Int = 1, idname: String, sontype: Int = 1, value: String = "", id: String = "", isEdit: Boolean = true, isMust: Boolean=false,isEnable:Boolean=true) : this() {
        this.key = key
        this.value = value
        this.type = type
        this.idname = idname
        this.id = id
        this.sontype = sontype
        this.isEdit = isEdit
        this.isMust= isMust
        this.isEnable = isEnable
    }

//    constructor(key: String, poplistdata: List<MyDialog.DialogParam>, idname: String, value: String = "", id: String = "", isEdit: Boolean = true,isMust: Boolean=false,isEnable:Boolean=true,isMultiple:Boolean = false) : this() {
//        this.poplistdata.addAll(poplistdata)
//        this.type = type
//        this.idname = idname
//        this.id = id
//        this.value = value
//        this.isEdit = isEdit
//        this.key = key
//        this.isMust= isMust
//        this.isEnable = isEnable
//        this.isMultiple = isMultiple
//    }

    constructor(key: String, poplistdata: List<DialogParam>, idname: String, value: String = "", id: String = "", isEdit: Boolean = true, isMust: Boolean = false, isEnable: Boolean = true, columns: Int = 3, lines: Int = 1, type: Int = 5, isMore: Boolean = true,maxCount:Int = 0) : this() {
        this.poplistdata.addAll(poplistdata)
        this.idname = idname
        this.id = id
        this.value = value
        this.isEdit = isEdit
        this.key = key
        this.isMust = isMust
        this.isEnable = isEnable
        this.radioColumn = columns
        this.radioLine = lines
        this.type = type
        this.isMore = isMore
        this.radioMaxCount = maxCount
        if(maxCount>0){
            if (poplistdata.size <= maxCount) {
                this.isMore = false
            }
        }else {
            if (poplistdata.size <= radioColumn) {
                this.isMore = false
            }
        }
    }


    //参数id
    @get:Bindable
    var id = ""
        set(value) {
            field = value
            notifyPropertyChanged(BR.id)

        }
    //参数属性名称
    var idname = ""
    var ikey = ""
    var spec_select = 1

    @get:Bindable
    var value: String = ""
        set(value) {
            field = value
            notifyPropertyChanged(BR.value)

        }
    @get:Bindable
    var show: Boolean = true
        set(value) {
            field = value
            notifyPropertyChanged(BR.show)

        }
    //显示类型 用于编辑购车记录节面
    var type: Int = 1
    //显示子类型 用于编辑购车记录节面
    var sontype: Int = 1
    @get:Bindable
    var IsSelect: Boolean = false
        set(isSelect) {
            field = isSelect
            notifyPropertyChanged(BR.isSelect)

        }
//    var poplistdata = ArrayList<MyDialog.DialogParam>()
    @get:Bindable
    var poplistdata = ArrayList<DialogParam>()
        set(value) {
            field = value
            notifyPropertyChanged(BR.poplistdata)
        }

    //选项每行个数
    @get:Bindable
    var radioColumn = 3
        set(value) {
            field = value
            notifyPropertyChanged(BR.radioColumn)
        }
    //选项每行个数
    @get:Bindable
    var radioLine = 1
        set(value) {
            field = value
            notifyPropertyChanged(BR.radioColumn)
        }

    //选项最大个数
    @get:Bindable
    var radioMaxCount = 0
        set(value) {
            field = value
            notifyPropertyChanged(BR.radioMaxCount)
        }

    override fun toString(): String {
        return "{key:$key,show:$show,value:$value}"
    }

}